<?php
/**
 * This is main KPI selection screen
 * for display
 * 
 */

use Fox\Html\AnchorObject;
use Fox\Generator;
use Orx\Kpi\Messages;
use Orx\Kpi;
use Fox\Html\Screen;

$screen = new Screen('sKpi');
$screen->method(Screen::METHOD_GET)
		->pageTitle(Msg(Messages::BUNDLE,Messages::KPI_LIST));
		
$kpis = Fox\Dao::finder(Kpi::className())
			->where('active = ?',array(1))
			->find();
$grid = new Fox\Grid('kpis');

$grid->fieldcat(array(
				array('kpi_label','label'),
				array('kpi_description','description'),
				array('kpi_category','category'),
				array('kpi_periodicity','periodicity'),
				array('kpi_threshold','threshold'),
				array('kpi_target','target')
				));
$grid->fieldcat()->switchToObjectMode();
$grid->fieldcat()->setGenerators(array(
	'label' => Generator::call('label'),
	'description' => Generator::call('description'), 
	'category' => Generator::useFunction(function($data){
		return $data->category()->label();
	}), 
	'periodicity' => Generator::useFunction(function($data){
		return $data->periodicity()->label();
	}), 
));
$grid->fieldcat()->field('periodicity')->align('center',true);
$grid->fieldcat()->field('category')->align('center',true);
$grid->fieldcat()->setFieldAttr(array('label','description'), 'setAnchor',
					new AnchorObject(Generator::url('kpi','show'),
						array('inlineid' => Generator::call('getInLineId'))));
$grid->initialize($kpis);
$html = $screen->display();
$html .=$grid->display();
return $html;